#ifndef PRESCRIPTIONWIDGET_H
#define PRESCRIPTIONWIDGET_H

#include <QWidget>
#include <QJsonObject>
#include "../../../Common/models.h"
#include "../../../Common/protocol.h"

namespace Ui {
class PrescriptionWidget;
}

class PrescriptionWidget : public QWidget {
    Q_OBJECT
    
public:
    explicit PrescriptionWidget(const Doctor& doctor, QWidget *parent = nullptr);
    explicit PrescriptionWidget(const Doctor& doctor, const Patient& patient, QWidget *parent = nullptr);
    explicit PrescriptionWidget(const Doctor& doctor, const Patient& patient, int appointmentId, int recordId, QWidget *parent = nullptr);
    ~PrescriptionWidget();
    
signals:
    void prescriptionCreated();  // 处方创建成功信号
    void backToPatientDetail();  // 返回患者详情信号
    
private slots:
    void on_saveButton_clicked();
    void on_clearButton_clicked();
    void on_backButton_clicked();  // 返回按钮点击槽函数
    void onSelectMedicineClicked();  // 选择药物按钮点击槽函数
    void onMessageReceived(MessageType type, const QJsonObject& data);
    
private:
    void setupPatientInfo(const Patient& patient);
    void addMedicineSelectButton();  // 添加药物选择按钮
    
    Ui::PrescriptionWidget *ui;
    Doctor m_doctor;
    bool m_hasPatient;
    int m_appointmentId;  // 预约ID，用于保存到处方
};

#endif // PRESCRIPTIONWIDGET_H

